<template>
  <view class="query_container">
    <!-- 商品展示区域 -->
    <scroll-view
      :scroll-y="true"
      class="scroll-y"
      @scrolltolower="scroll_bottom"
    >
      <view class="empty" style="text-align: center" v-if="goodList.length == 0"
        >暂无推广商品</view
      >
      <good-info :goodsList="goodList" @reload="reload"></good-info>
    </scroll-view>

    <!-- <van-empty description="描述文字" /> -->

    <!-- 商品展示区域 -->

    <van-toast id="van-toast" />
    <van-dialog id="van-dialog" zIndex="99999999999" />
  </view>
</template>

<script>
import GoodInfo from "../components/good_info";
import Dialog from "../../wxcomponents/vant/dialog/dialog";
import { show_tj_goods } from "../../utils/imapi";
export default {
  props: {},
  components: {
    GoodInfo,
  },
  data() {
    return {
      value: "",
      option1: [
        { text: "全部", value: "" },
        { text: "仓库中", value: 0 },
        { text: "上架审核", value: 1 },
        { text: "提审中", value: 2 },
        { text: "审核成功", value: 3 },
        { text: "审核失败", value: 4 },
      ],
      value1: 0,
      goodList: [],
      mode_show: false,
      good_info: {},
    };
  },
  computed: {},
  watch: {},
  onLoad(options) {
    console.log(options);
    if (options.type == "near") {
      this.mch_type = "near";
    }
    console.log(this.mch_type);
    this.query_all_goods();
  },
  onReady() {},
  onShow() {},
  methods: {
    async query_all_goods() {
      try {
        const data = await show_tj_goods();
        console.log(data);
        if (data.code == 0) {
          if (data.data == null) {
            this.goodList = [];
          } else {
            this.goodList.push({goods:data.data});
          }

          console.log(this.goodList);
        }
      } catch (error) {}
    },
    reload() {
      this.queryparam.page_index = 1;
      this.query_all_goods();
    },
    status_change(e) {
      console.log(e.detail);
      this.queryparam.goods_status = e.detail;
      console.log(this.queryparam.goods_status);
    },
    inputchange(e) {
      console.log(e.detail);
      this.queryparam.title = e.detail.value;
    },
    reset() {
      this.queryparam = {
        goods_status: "",
        page_index: 1,
        page_size: 10,
        title: "",
      };
      this.query_all_goods();
    },
    thequery() {
      console.log(this.queryparam.title);
      this.query_all_goods();
    },

    async scroll_bottom() {
      console.log("触底了");
      this.queryparam.page_index++;
      try {
        const data = await query_all_goods(this.queryparam);
        const toast = this.$toast.loading("加载中");
        if (data.code == 0) {
          this.goodList.push(...data.data);
          console.log(data);
          toast.clear();
          if (data.data.length == 0) {
            this.queryparam.page_index--;

            this.$toast("全部加载");
          }
        }
      } catch (error) {}
    },
    close_mode() {},
  },
  onReachBottom() {},
  onHide() {},
};
</script>

<style scoped lang="scss" scoped>
.query_container {
  .scroll-y {
    height: 1200upx;
  }
}
</style>
